﻿using System;
using System.Collections.Generic;
using ENail.Domain.Core;
using System.Linq;
using Equation.Enterprise.Framework.Domain.Model;
using Equation.Enterprise.Framework.Web.Model;
using Equation.Enterprise.Utilities.DesignByContract;
using System.ComponentModel.DataAnnotations;
using MvcContrib.Pagination;

namespace ENail.Portal.Web.Models
{
    public class TaskViewModel : BaseViewModel<Int32>
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Service { get; set; }
        public int Made { get; set; }
        public int Waiting { get; set; }

    }
    public class TaskListViewItem : BaseViewModel<Int32>
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Service { get; set; }
        public int Made { get; set; }
        public int Waiting { get; set; }
    }

    public class TaskViewModelMapper : ViewModelMapper<TaskViewModel, Task>
    {
        public TaskViewModelMapper()
        {
        }

        public override void MapDomainToView(Task TaskDomainModel, TaskViewModel TaskViewModel)
        {
            Check.Require(TaskDomainModel != null);
            Check.Require(TaskViewModel != null);

            TaskViewModel.Id = TaskDomainModel.Id;
            TaskViewModel.FirstName = TaskDomainModel.FirstName;
            TaskViewModel.LastName = TaskDomainModel.LastName;
            TaskViewModel.Service = TaskDomainModel.Service;
            TaskViewModel.Made = TaskDomainModel.Made;
            TaskViewModel.Waiting = TaskDomainModel.Waiting;
        }

        public override void MapViewToDomain(TaskViewModel TaskViewModel, Task TaskDomainModel)
        {
            Check.Require(TaskDomainModel != null);
            Check.Require(TaskViewModel != null);

            TaskDomainModel.FirstName = TaskViewModel.FirstName;
            TaskDomainModel.LastName = TaskViewModel.LastName;
            TaskDomainModel.Made = TaskViewModel.Made;
            TaskDomainModel.Waiting = TaskViewModel.Waiting;
        }
    }
    public class TaskListViewModelMapper : ListViewModelMapper<TaskListViewItem, Task>
    {
        public const int DEFAULT_PAGE = 1;
        public const int PAGE_SIZE = 999;

        public override void MapDomainToView(List<Task> domainModel, GenericListViewModel<TaskListViewItem> viewModel)
        {
            Check.Require(domainModel != null);
            Check.Require(viewModel != null);

            viewModel.List = (from e in domainModel
                              where
                                  (viewModel.Filter == null || viewModel.Filter.Trim() == "" ||
                                   e.FirstName.ToLower().Contains(viewModel.Filter.Trim().ToLower()) || e.LastName.ToLower().Contains(viewModel.Filter.Trim().ToLower()))
                              select new TaskListViewItem
                              {
                                  Id = e.Id,
                                  Service = e.Service,
                                  FirstName = e.FirstName,
                                  LastName = e.LastName,
                                  Made = e.Made,
                                  Waiting = e.Waiting
                              })
                              .OrderBy(x => x.FirstName);
                              //.AsPagination(viewModel.Page ?? DEFAULT_PAGE, PAGE_SIZE);
        }

        public override void MapViewToDomain(GenericListViewModel<TaskListViewItem> viewModel, List<Task> domainModel)
        {
            throw new NotImplementedException();
        }
    }

}